﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Common;
using Tedu.ARPGDemo.Character;

namespace ARPGDemo.Skill
{
    /// <summary>
    /// 扇形选区
    /// </summary>
    public class SectorAttackSelector : IAttackSelector
    {
        public Transform[] SelectTarget(SkillData data, Transform skillTF)
        {
            //获取周围敌人
            var targets = skillTF.CalculateAroundObject(data.attackDistance, data.attackAngle, data.attackTargetTags);
            //此处报错原因，子物体也有Play标签，导致获取的周边物体有子物体，而子物体上没有CharacterStatus组件
            //if (targets.Length != 0)//自加
            //{
                //筛选活的的敌人
                targets = targets.FindAll(t => t.GetComponent<CharacterStatus>().HP > 0);//此处有bug，targets为null时
            //}
           
            if (targets.Length == 0)
            {
                return null;
            }

            if (data.attackType == SkillAttackType.Single)
            {
                //如果单攻
                return new Transform[] { targets.GetMin(t => Vector3.Distance(t.position, skillTF.position)) };
            }
            else
            {
                //群攻
                return targets;
            }
        }
    }
}

